/******************************************************************************/
package jamie.org.sil.www.usxUtils;


/******************************************************************************/
/**
   A link manager.
   <p>

   There is a common requirement to be able to generate the equivalent
   of HTML anchor tags so as to link from one place to another.
   <p>

   For this purpose, we need unique strings which can be placed in the main
   text (so that other things can point back to them) and in the subsidiary
   text (so that the main text can point to them).  The present class
   handles this, producing distinctive strings which may be useful when
   debugging.
*/

public class LinkManager
{
  /****************************************************************************/
  /****************************************************************************/
  /**                                                                        **/
  /**                                Public                                  **/
  /**                                                                        **/
  /****************************************************************************/
  /****************************************************************************/

  /****************************************************************************/
  /**
      Singleton.

      @return Singleton instance.
   */

  public static LinkManager instance ()
  {
    if (null == m_Instance) m_Instance = new LinkManager();
    return m_Instance;
  }


  /****************************************************************************/
  /**
      Get a new anchor which we can place in a footnote file and point to from
      scripture.  (Note that the anchor is devoid of any filename -- that
      needs to be handled separately.)

      @return Anchor.
   */

  public String getNewAnchorInFootnotePointedToByScripture ()
  {
    ++m_S2F;
    return getPreviousAnchorInFootnotePointedToByScripture();
  }


  /****************************************************************************/
  /**
      Get a new anchor which we can place in an introduction file and
      point to from scripture.  (Note that the anchor is devoid of any
      filename -- that needs to be handled separately.)

      @return Anchor.
   */

  public String getNewAnchorInIntroductionPointedToByScripture ()
  {
    ++m_S2I;
    return getPreviousAnchorInIntroductionPointedToByScripture();
  }


  /****************************************************************************/
  /**
      Get a new anchor which we can place in an xref file and
      point to from scripture.  (Note that the anchor is devoid of any
      filename -- that needs to be handled separately.)

      @return Anchor.
   */

  public String getNewAnchorInXrefPointedToByScripture ()
  {
    ++m_S2X;
    return getPreviousAnchorInXrefPointedToByScripture();
  }


  /****************************************************************************/
  /**
      Get a new anchor which we can place in a scripture file and point to from
      a footnote.  (Note that the anchor is devoid of any filename -- that
      needs to be handled separately.)

      @return Anchor.
   */

  public String getNewAnchorInScripturePointedToByFootnote ()
  {
    ++m_F2S;
    return getPreviousAnchorInScripturePointedToByFootnote();
  }


  /****************************************************************************/
  /**
      Get a new anchor which we can place in a scripture file and point to from
      an introduction.  (Note that the anchor is devoid of any filename -- that
      needs to be handled separately.)

      @return Anchor.
   */

  public String getNewAnchorInScripturePointedToByIntroduction ()
  {
    ++m_I2S;
    return getPreviousAnchorInScripturePointedToByIntroduction();
  }


  /****************************************************************************/
  /**
      Get a new anchor which we can place in a scripture file and point to from
      an xref.  (Note that the anchor is devoid of any filename -- that
      needs to be handled separately.)

      @return Anchor.
   */

  public String getNewAnchorInScripturePointedToByXref ()
  {
    ++m_X2S;
    return getPreviousAnchorInScripturePointedToByXref();
  }


  /****************************************************************************/
  /**
      Get the most recent anchor which we can place in a footnote
      file and point to from scripture.  (Note that the anchor is
      devoid of any filename -- that needs to be handled separately.)

      @return Anchor.
   */

  public String getPreviousAnchorInFootnotePointedToByScripture ()
  {
    return "S2F_" + Integer.toString(m_S2F);
  }


  /****************************************************************************/
  /**
      Get the most recent anchor which we can place in an introduction file
      file and point to from scripture.  (Note that the anchor is
      devoid of any filename -- that needs to be handled separately.)

      @return Anchor.
   */

  public String getPreviousAnchorInIntroductionPointedToByScripture ()
  {
    return "S2I_" + Integer.toString(m_S2I);
  }


  /****************************************************************************/
  /**
      Get the most recent anchor which we can place in an xref file
      file and point to from scripture.  (Note that the anchor is
      devoid of any filename -- that needs to be handled separately.)

      @return Anchor.
   */

  public String getPreviousAnchorInXrefPointedToByScripture ()
  {
    return "S2X_" + Integer.toString(m_S2X);
  }


  /****************************************************************************/
  /**
      Get a the most recent anchor which we can place in a scripture
      file and point to from a footnote.  (Note that the anchor is
      devoid of any filename -- that needs to be handled separately.)

      @return Anchor.
   */

  public String getPreviousAnchorInScripturePointedToByFootnote ()
  {
    return "F2S_" + Integer.toString(m_F2S);
  }


  /****************************************************************************/
  /**
      Get a the most recent anchor which we can place in a scripture
      file and point to from an introduction.  (Note that the anchor is
      devoid of any filename -- that needs to be handled separately.)

      @return Anchor.
   */

  public String getPreviousAnchorInScripturePointedToByIntroduction ()
  {
    return "F2I_" + Integer.toString(m_I2S);
  }


  /****************************************************************************/
  /**
      Get a the most recent anchor which we can place in a scripture
      file and point to from an xref.  (Note that the anchor is
      devoid of any filename -- that needs to be handled separately.)

      @return Anchor.
   */

  public String getPreviousAnchorInScripturePointedToByXref ()
  {
    return "X2S_" + Integer.toString(m_X2S);
  }





  /****************************************************************************/
  /****************************************************************************/
  /**                                                                        **/
  /**                                Private                                 **/
  /**                                                                        **/
  /****************************************************************************/
  /****************************************************************************/

  /****************************************************************************/
  /* Constructor. */

  private LinkManager ()
  {
  }


  /****************************************************************************/
  private static LinkManager m_Instance = null;
  private int m_I2S = 0;
  private int m_F2S = 0;
  private int m_S2F = 0;
  private int m_S2I = 0;
  private int m_S2X = 0;
  private int m_X2S = 0;
}
